<?php
/*
	Copyright 2006, 2007, 2008, 2009, 2010 Bastiaan Grutters
    
    This file is part of Ages of Strife website.

    Ages of Strife website is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Ages of Strife website is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Ages of Strife website.  If not, see <http://www.gnu.org/licenses/>.
 */
include( "../global/initialize.php");

aos_header( 'Morale' );

$query = "SELECT morale, payday, last_battle, recruits " .
		"FROM ruler " .
		"WHERE ruler_id = " . $_SESSION['ruler_id'];
$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$morale = $row[ 'morale' ];
$payday = $row[ 'payday' ];
$recruits = $row[ 'recruits' ];
if( $row[ 'last_battle' ] > 0 ) {
	$last_battle = getCurrentTurn() - $row[ 'last_battle' ];
	if( $last_battle == 1 ) {
		$battle_string = translate( "Yesterday" );
	}
	else if( $last_battle == 0 ) {
		$battle_string = translate( "Today" );
	}
	else if( $last_battle < 0 ) {
		$battle_string = translate( "Now" );
	}
	else {
		$battle_string = number_format( $last_battle ) . " " . translate( "days ago" );
	}
}
else {
	$battle_string = translate( "Never" );
}


$set_payday = 0;
$yes_no = "Yes";
if( $payday == 0 ) {
	$set_payday = 1;
	$yes_no = "No";
}

$morale_string = get_morale_string( $morale );
$total_military = get_total_military();
$total_deployed_military = get_total_deployed_military();
$total_reserve_military = get_total_reserves_military();
?>
					<div class="blok">
						<strong><?php transprint( 'Military morale' ); ?></strong><br />
						<?php transprint( 'Total size' ); ?>: <?php print( number_format( $total_military ) ); ?><br />
						<?php transprint( 'Deployed' ); ?>: <?php print( number_format( $total_deployed_military ) ); ?><br />
						<?php transprint( 'Recruits' ); ?>: <strong class="recruits"><?php print( number_format( $recruits ) ); ?></strong><br />
						<?php transprint( 'Reserves' ); ?>: <strong class="recruits"><?php print( number_format( $total_reserve_military ) ); ?></strong><br />
						<a href="../aosmanual/concepts.php#military morale"><?php transprint( 'Morale' ); ?></a>: <?php print( $morale_string ); ?><br />
						<?php transprint( 'Last significant battle' ); ?>: <?php print( $battle_string ); ?><br />
<?php
//print( "Your morale value = $morale<br />" );

if( $morale > 0.8 ) {
	print( translate( "During combat you will get a 2% defense and offense bonus due to high morale." ) . "<br />" );
}
else if( $morale <= 0.2 ) {
	print( translate( "The terrible military morale has spread to your production! Food, coal and iron production is reduced by 50%, recruitment has been reduced by 80%." ) . "<br />" );
}
else if( $morale <= 0.4 ) {
	print( translate( "The low military morale has affected your production! Food, coal and iron production is reduced by 20%, recruitment has been reduced by 40%." ) . "<br />" );
}

// You pay each soldier 0.08 gold
$gold_cost = round( $total_military * 0.08 );
if( $total_military > 1000 ) {
?>
						<br />
						<strong><?php transprint( 'Pay soldiers' ); ?></strong><br />
						<?php transprint( 'Gold cost' ); ?>: <strong class="gold"><?php print( number_format( $gold_cost ) ); ?></strong><br />
						<?php transprint( 'Pay soldiers as soon as enough gold is available' ); ?>: <strong><?php print( $yes_no ); ?></strong><br />
						<form method="post" action="set_payday.php">
							<input type="hidden" name="payday" value="<?php print( $set_payday ); ?>" />
							<input type="submit" value="<?php transprint( 'Change payment' ); ?>" /><br />
						</form>
						<small>
							<?php transprint( 'If set to yes, your treasurer will pay the soldiers at the end of the game day, if enough gold is available.' ); ?><br />
							<?php transprint( 'If you don\'t have enough gold available he will wait until it is.' ); ?><br />
							<?php transprint( 'When a payment is made to the soldiers this option is set back to "no" automatically.' ); ?>
						</small><br />
<?php
}
?>
						<br />
						<?php transprint( 'Note: The longer your soldiers have been without any significant battle, the faster their morale will decline.' ); ?><br />
					</div>
					<br />
					<div class="blok">
						<strong><?php transprint( 'Dismiss recruits' ); ?></strong><br />
						<form method="post" action="dismiss_recruits.php">
							<?php transprint( 'Dismiss' ); ?> <input size="5" type="text" name="amount" value="0" /> <?php transprint( 'recruits' ); ?><br />
							<input type="submit" value="<?php transprint( 'confirm' ); ?>" /><br />
						</form>
						<br />
						<?php transprint( 'You might want to dismiss some recruits if you have too many, since they are paid as well to improve morale. Keep in mind though that there is no way to get these recruits back, you will have to gather new ones through recruiting.' ); ?>
					</div>
<?php
aos_footer();
?>
